package com.qf.purchasing.controller;

import com.github.pagehelper.PageInfo;
import com.qf.common.base.result.RespResult;
import com.qf.purchasing.qo.ScheduleQO;
import com.qf.purchasing.service.ScheduleService;
import com.qf.purchasing.vo.ScheduleVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/goods")
//类上，tags=模块名
@Api(tags = "采购计划 ")
public class ScheduleController {
    @Resource
    private ScheduleService scheduleService;

    @GetMapping("/list")
    //接口上，接口描述。value=接口名
    @ApiOperation("分页查询商品")
    //接口上，参数注解
    @ApiImplicitParams({
            //                参数名，       参数说明，         是否必填， 参数请求类型：query,header,path  参数数据类型，   参数默认值           示例
            @ApiImplicitParam(name = "page", value = "当前页数", required = false, paramType = "query", dataType = "java.lang.Integer", defaultValue = "1", example = "page=1"),
            @ApiImplicitParam(name = "size", value = "展示量", required = false, paramType = "query", dataType = "java.lang.Integer", defaultValue = "10"),
            @ApiImplicitParam(name = "title", value = "搜索标题", required = false),
            @ApiImplicitParam(name = "year", value = "搜索年份", required = false)
    })
    public PageInfo<ScheduleVO> list(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "5") int size, @RequestParam(required = false) String title, @RequestParam(required = false) String year) {
        return scheduleService.query(page, size, title, year);
    }


    @PutMapping("/delete1")
    @ApiOperation("删除采购计划")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "id", value = "采购计划id", required = true)
    )
    public RespResult<String> RemoveScheduleOne(int id) {
        return scheduleService.deleteScheduleOne(id);
    }


    @PutMapping("/delete2")
    @ApiOperation("多选删除采购计划")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "ids", value = "采购计划id数组", required = true)
    )
    public RespResult<String> RemoveSchedules(int[] ids) {
        return scheduleService.deleteSchedules(ids);
    }

    @PostMapping("/insert")
    @ApiOperation("添加采购计划")
    public RespResult<String> addSchedule(ScheduleQO scheduleQO) {
        return scheduleService.insert(scheduleQO);
    }

    @PutMapping("/update")
    @ApiOperation("修改采购计划")
    public RespResult<String> modifySchedule(ScheduleQO scheduleQO) {
        return scheduleService.modify(scheduleQO);
    }

    @GetMapping("/select")
    @ApiOperation("根据id查询采购计划")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "sid", value = "采购计划id", required = true)
    )
    public RespResult<ScheduleVO> queryScheduleById(int sid) {
        return scheduleService.selectScheduleById(sid);
    }

    @PutMapping("/recall")
    @ApiOperation("撤回功能")
    public RespResult<String> recall() {
        return scheduleService.recallSchedule();
    }


}
